package com.ruicar.afs.cloud.apply.contract.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.apply.common.dto.ApplySigningInfoDTO;
import com.ruicar.afs.cloud.apply.common.entity.ApplyBankCard;
import com.ruicar.afs.cloud.apply.common.feign.ApplySigningFeign;
import com.ruicar.afs.cloud.apply.contract.mapper.ApplyBankCardMapper;
import com.ruicar.afs.cloud.apply.contract.service.ApplyBankCardService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: Lee
 * @date: 2020/5/13 21:19
 * @description:
 */
@Service
@Slf4j
@AllArgsConstructor
public class ApplyBankCardServiceImpl extends ServiceImpl<ApplyBankCardMapper, ApplyBankCard> implements ApplyBankCardService {

    private final ApplySigningFeign signingFeign;

    /**
     * @return
     * @Description: 签约申请四要素验证
     * @Author: TIANKAI
     * @Date: 2020/8/11
     */
    @Override
    public String custSigningApply(ApplySigningInfoDTO signingInfoDTO) {
        JSONObject jsonObject = null;
        String message = null;
        try {
            jsonObject = signingFeign.doVerify(signingInfoDTO);
        } catch (Exception e) {
            log.info("发送四要素签约申请失败", e.getMessage());
        }
        try {
            jsonObject = (JSONObject) jsonObject.get("status");
            String code = (String) jsonObject.get("code");
            if ("000000".equals(code)) {
            } else {
                message = (String) jsonObject.get("message");
            }

        } catch (Exception e) {
            log.info("接收四要素签约申请信息失败", e.getMessage());
        }
        return message;
    }

    /**
     * @Description: 短信验证接口
     * @Author: TIANKAI
     * @Date: 2020/8/11
     */
    @Override
    public void custMessageVerify(ApplySigningInfoDTO signingInfoDTO) {
        JSONObject jsonObject = null;
        try {
            //jsonObject = signingFeign.doSign(signingInfoDTO);
        } catch (Exception e) {
            log.info("发送短信验证接口失败", e.getMessage());
        }
        try {
            jsonObject = (JSONObject) jsonObject.get("status");
            String code = (String) jsonObject.get("code");
            if ("0000".equals(code)) {
            } else {
                String message = (String) jsonObject.get("message");
            }
        } catch (Exception e) {
            log.info("接收短信验证接口失败", e.getMessage());
        }
    }

    @Override
    public ApplyBankCard getBankCardByApplyNo(String applyNo) {
        ApplyBankCard applyBankCard = this.baseMapper.selectOne(Wrappers.<ApplyBankCard>query().lambda().eq(ApplyBankCard::getApplyNo, applyNo));
        return applyBankCard;
    }
}
